(function() {
  var body_dropdown_items, check_submit, express, fs, iced, id_validate, pgsql, router, uuid, __iced_k, __iced_k_noop;

  iced = require('iced-runtime');
  __iced_k = __iced_k_noop = function() {};

  express = require('express');

  pgsql = require('pg');

  fs = require('fs');

  uuid = require('uuid');

  router = express.Router();

  module.exports = router;

  router.all('/', function(req, res, next) {
    var client, done, err, records, result, uncheck_clause, where_clause, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 12
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        where_clause = "( p.uuid like $1 or p.acct_no like $1 or p.acct_name like $1 or p.notes like $1 or m1.merno like $1 or m1.name like $1 or t1.termid like $1 or m2.merno like $1 or m2.name like $1 or t2.termid like $1 or m3.merno like $1 or m3.name like $1 )";
        uncheck_clause = '1 = 1';
        if (!res.locals.page_perms.check) {
          uncheck_clause = "p.inputer = '" + req.session.userinfo.uuid + "'";
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select count(*)::int as count from pay_p1 as p left join pay_merch as m1 on m1.uuid = json_extract_path_text(p.check_data, 'data', 't20_merid') left join pay_terms as t1 on t1.uuid = json_extract_path_text(p.check_data, 'data', 't20_termid') left join pay_merch as m2 on m2.uuid = json_extract_path_text(p.check_data, 'data', 'tz0_merid') left join pay_terms as t2 on t2.uuid = json_extract_path_text(p.check_data, 'data', 'tz0_termid') left join pay_merch as m3 on m3.uuid = json_extract_path_text(p.check_data, 'data', 'pay_merid') where " + where_clause + " and checked = false and " + uncheck_clause, ['%' + res.locals.keyword + '%'], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 42
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          res.locals.total += result.rows[0].count;
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
            });
            client.query("select count(*)::int as count from pay_p1 as p left join pay_merch as m1 on m1.uuid = p.t20_merid left join pay_terms as t1 on t1.uuid = p.t20_termid left join pay_merch as m2 on m2.uuid = p.tz0_merid left join pay_terms as t2 on t2.uuid = p.tz0_termid left join pay_merch as m3 on m3.uuid = p.pay_merid where " + where_clause + " and checked = true", ['%' + res.locals.keyword + '%'], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 55
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            res.locals.total += result.rows[0].count;
            records = [];
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
              });
              client.query("select p.*, json_extract_path_text(p.check_data, 'data', 'pay_chnl') as pay_chnl, json_extract_path_text(p.check_data, 'data', 'acct_no') as acct_no, json_extract_path_text(p.check_data, 'data', 'acct_name') as acct_name, json_extract_path_text(p.check_data, 'data', 'acct_cred_type') as acct_cred_type, json_extract_path_text(p.check_data, 'data', 'acct_cred_no') as acct_cred_no, json_extract_path_text(p.check_data, 'data', 'acct_bank_code') as acct_bank_code, json_extract_path_text(p.check_data, 'data', 'acct_bank_name') as acct_bank_name, json_extract_path_text(p.check_data, 'data', 'acct_mobile') as acct_mobile, json_extract_path_text(p.check_data, 'data', 'notes') as notes, m1.merno as t20_merno, m1.name as t20_mername, t1.termid as t20_termid, m2.merno as tz0_merno, m2.name as tz0_mername, t2.termid as tz0_termid, m3.merno as pay_merno, m3.name as pay_mername, u1.realname as input_user from pay_p1 as p left join pay_merch as m1 on m1.uuid = json_extract_path_text(p.check_data, 'data', 't20_merid') left join pay_terms as t1 on t1.uuid = json_extract_path_text(p.check_data, 'data', 't20_termid') left join pay_merch as m2 on m2.uuid = json_extract_path_text(p.check_data, 'data', 'tz0_merid') left join pay_terms as t2 on t2.uuid = json_extract_path_text(p.check_data, 'data', 'tz0_termid') left join pay_merch as m3 on m3.uuid = json_extract_path_text(p.check_data, 'data', 'pay_merid') left join web_users as u1 on u1.uuid = p.inputer where " + where_clause + " and checked = false and " + uncheck_clause + " order by serial desc offset $2::int limit $3::int", ['%' + res.locals.keyword + '%', res.locals.offset, res.locals.page_rows], __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return result = arguments[1];
                  };
                })(),
                lineno: 95
              }));
              __iced_deferrals._fulfill();
            })(function() {
              if (err) {
                done(client);
                return next(err);
              }
              records.push.apply(records, result.rows);
              (function(__iced_k) {
                __iced_deferrals = new iced.Deferrals(__iced_k, {
                  parent: ___iced_passed_deferral,
                  filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
                });
                client.query("select p.*, m1.merno as t20_merno, m1.name as t20_mername, t1.termid as t20_termid, m2.merno as tz0_merno, m2.name as tz0_mername, t2.termid as tz0_termid, m3.merno as pay_merno, m3.name as pay_mername, u1.realname as input_user, u2.realname as check_user from pay_p1 as p left join pay_merch as m1 on m1.uuid = p.t20_merid left join pay_terms as t1 on t1.uuid = p.t20_termid left join pay_merch as m2 on m2.uuid = p.tz0_merid left join pay_terms as t2 on t2.uuid = p.tz0_termid left join pay_merch as m3 on m3.uuid = p.pay_merid left join web_users as u1 on u1.uuid = p.inputer left join web_users as u2 on u2.uuid = p.checker where " + where_clause + " and checked = true order by serial desc offset $2::int limit $3::int", ['%' + res.locals.keyword + '%', res.locals.offset, res.locals.page_rows], __iced_deferrals.defer({
                  assign_fn: (function() {
                    return function() {
                      err = arguments[0];
                      return result = arguments[1];
                    };
                  })(),
                  lineno: 120
                }));
                __iced_deferrals._fulfill();
              })(function() {
                if (err) {
                  done(client);
                  return next(err);
                }
                records.push.apply(records, result.rows);
                done();
                return res.render('p1/index', {
                  records: records
                });
              });
            });
          });
        });
      };
    })(this));
  });

  body_dropdown_items = function(req, res, next) {
    var client, done, err, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 128
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select t.uuid, t.termid, t.shaded, m.inside as mer_inside, m.chnl as mer_chnl, m.name as mer_name, m.merno as mer_no from pay_terms as t left join pay_merch as m on m.uuid = t.merid where t.disabled = false and m.chnl = 1 and m.inside = false and json_extract_path_text(m.trctl, 'trcodes', 't20') = 'true' order by t.ctime desc", __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 141
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          res.locals.t20_terms = result.rows;
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
            });
            client.query("select t.uuid, t.termid, t.shaded, m.inside as mer_inside, m.chnl as mer_chnl, m.name as mer_name, m.merno as mer_no from pay_terms as t left join pay_merch as m on m.uuid = t.merid where t.disabled = false and m.chnl = 1 and m.inside = true and json_extract_path_text(m.trctl, 'trcodes', 'tz0') = 'true' order by t.ctime desc", __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 155
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            res.locals.tz0_terms = result.rows;
            done();
            return next();
          });
        });
      };
    })(this));
  };

  id_validate = function(id_no) {
    var coefficients, cv, i, sum , v, _i, _len;
    coefficients = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10,  5,  8, 4,  2];
    cv = '10X98765432';
    sum  =  0;
    for (i = _i = 0, _len = coefficients.length; _i < _len; i = ++_i) {
      v = coefficients[i];
      sum += v * id_no[i];
    }
    return cv[sum  %  11] === id_no[17];
  };

  check_submit = function(req, res, next) {
    var k, _i, _len, _ref;
    _ref = ['t20_termid', 'tz0_termid', 'pay_chnl', 'pay_merid', 'acct_no'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    if (req.body.acct_name) {
      req.body.acct_name = req.body.acct_name.replace(/\s/g, '');
    }
    if (req.body.acct_cred_type === '1') {
      if (req.body.acct_cred_no) {
        if (req.body.acct_cred_no.length !== 18) {
          return next(new Error('收款账号开户人身份证号码长度不等于18'));
        }
        if (!id_validate(req.body.acct_cred_no)) {
          return next(new Error('收款账号开户人身份证号码校验失败'));
        }
      }
    }
    req.app.set('notify_modified_time', moment().format('x'));
    return next();
  };

  router.get('/new', body_dropdown_items, function(req, res, next) {
    res.locals.breadcrumbs.push({
      'title': '新增配置'
    });
    return res.render('p1/new', {
      record: {}
    });
  });

  router.get('/new/:id', body_dropdown_items, function(req, res, next) {
    var client, done, err, record, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.locals.breadcrumbs.push({
      'title': '新增配置'
    });
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 202
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select * from pay_p1 where uuid = $1", [req.params.id], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 207
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          record = result.rows[0];
          if (!record || !record.check_data) {
            return next(new Error('未查询到记录或记录缺少待复核数据，请检查.'));
          }
          record.check_data.data.serial = record.serial;
          return res.render('p1/new', {
            record: record.check_data.data
          });
        });
      };
    })(this));
  });

  router.post('/new', check_submit, function(req, res, next) {
    var check_data, client, done, err, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 219
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select merid from pay_terms where uuid = $1", [req.body.t20_termid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 224
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          req.body.t20_merid = result.rows[0].merid;
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
            });
            client.query("select merid from pay_terms where uuid = $1", [req.body.tz0_termid], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 230
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            req.body.tz0_merid = result.rows[0].merid;
            check_data = {
              action: 1,
              data: req.body
            };
            check_data.acct_no_modified = true;
            (function(__iced_k) {
              if (req.body.uuid && req.body.uuid.length > 0) {
                (function(__iced_k) {
                  __iced_deferrals = new iced.Deferrals(__iced_k, {
                    parent: ___iced_passed_deferral,
                    filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
                  });
                  client.query("update pay_p1 set check_data = $1, checked = false, inputer = $2, input_time = CURRENT_TIMESTAMP where uuid = $3 and inputer = $4", [JSON.stringify(check_data), req.session.userinfo.uuid, req.body.uuid, req.session.userinfo.uuid], __iced_deferrals.defer({
                    assign_fn: (function() {
                      return function() {
                        err = arguments[0];
                        return result = arguments[1];
                      };
                    })(),
                    lineno: 247
                  }));
                  __iced_deferrals._fulfill();
                })(function() {
                  if (err) {
                    done(client);
                    return next(err);
                  }
                  return __iced_k();
                });
              } else {
                req.body.uuid = uuid.v4();
                (function(__iced_k) {
                  __iced_deferrals = new iced.Deferrals(__iced_k, {
                    parent: ___iced_passed_deferral,
                    filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
                  });
                  client.query("insert into pay_p1 ( uuid, inputer, check_data, t20_termid, tz0_termid ) values ( $1, $2, $3, $4, $5 )", [req.body.uuid, req.session.userinfo.uuid, JSON.stringify(check_data), req.body.t20_termid, req.body.tz0_termid], __iced_deferrals.defer({
                    assign_fn: (function() {
                      return function() {
                        err = arguments[0];
                        return result = arguments[1];
                      };
                    })(),
                    lineno: 262
                  }));
                  __iced_deferrals._fulfill();
                })(function() {
                  if (err) {
                    done(client);
                    return next(err);
                  }
                  return __iced_k();
                });
              }
            })(function() {
              done();
              return res.redirect('/p1');
            });
          });
        });
      };
    })(this));
  });

  router.post('/new/delete', function(req, res, next) {
    var client, done, err, k, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['serial', 'uuid'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 273
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("delete from pay_p1 where uuid = $1", [req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 279
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          req.app.set('notify_modified_time', moment().format('x'));
          return res.json({
            succ: true,
            redirect: '/p1'
          });
        });
      };
    })(this));
  });

  router.get('/edit/:id', body_dropdown_items, function(req, res, next) {
    var client, done, err, record, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.locals.breadcrumbs.push({
      'title': '修改配置'
    });
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 290
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select * from pay_p1 where uuid = $1", [req.params.id], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 295
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          if (!result.rows.length === 0) {
            return next(new Error('未查询到记录，请检查.'));
          }
          if (result.rows[0].checked) {
            record = result.rows[0];
          } else {
            record = result.rows[0].check_data.data;
            record.serial = result.rows[0].serial;
          }
          return res.render('p1/edit', {
            record: record
          });
        });
      };
    })(this));
  });

  router.post('/edit', check_submit, function(req, res, next) {
    var check_data, client, done, err, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 311
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select merid from pay_terms where uuid = $1", [req.body.t20_termid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 316
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          req.body.t20_merid = result.rows[0].merid;
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
            });
            client.query("select merid from pay_terms where uuid = $1", [req.body.tz0_termid], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 322
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            req.body.tz0_merid = result.rows[0].merid;
            check_data = {
              action: 2,
              data: req.body
            };
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
              });
              client.query("select count(*)::int as count from pay_p1 where uuid = $1 and acct_no = $2", [req.body.uuid, req.body.acct_no], __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return result = arguments[1];
                  };
                })(),
                lineno: 334
              }));
              __iced_deferrals._fulfill();
            })(function() {
              if (err) {
                done(client);
                return next(err);
              }
              check_data.acct_no_modified = result.rows[0].count === 0;
              (function(__iced_k) {
                __iced_deferrals = new iced.Deferrals(__iced_k, {
                  parent: ___iced_passed_deferral,
                  filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
                });
                client.query("update pay_p1 set check_data = $1, checked = false, inputer = $2, input_time = CURRENT_TIMESTAMP where uuid = $3", [JSON.stringify(check_data), req.session.userinfo.uuid, req.body.uuid], __iced_deferrals.defer({
                  assign_fn: (function() {
                    return function() {
                      err = arguments[0];
                      return result = arguments[1];
                    };
                  })(),
                  lineno: 346
                }));
                __iced_deferrals._fulfill();
              })(function() {
                if (err) {
                  done(client);
                  return next(err);
                }
                done();
                return res.redirect('/p1');
              });
            });
          });
        });
      };
    })(this));
  });

  router.get('/edit/delete/:id', function(req, res, next) {
    var client, done, err, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 353
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("update pay_p1 set checked = true, check_data = null where uuid = $1", [req.params.id], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 360
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          req.app.set('notify_modified_time', moment().format('x'));
          return res.redirect('/p1');
        });
      };
    })(this));
  });

  router.post('/delete', function(req, res, next) {
    var check_data, client, done, err, k, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['serial', 'uuid'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 373
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select * from pay_p1 where uuid = $1", [req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 380
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          check_data = {
            action: 3,
            data: result.rows[0]
          };
          (function(__iced_k) {
            __iced_deferrals = new iced.Deferrals(__iced_k, {
              parent: ___iced_passed_deferral,
              filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
            });
            client.query("update pay_p1 set checked = false, check_data = $1, inputer = $2, input_time = CURRENT_TIMESTAMP where uuid = $3", [JSON.stringify(check_data), req.session.userinfo.uuid, req.body.uuid], __iced_deferrals.defer({
              assign_fn: (function() {
                return function() {
                  err = arguments[0];
                  return result = arguments[1];
                };
              })(),
              lineno: 391
            }));
            __iced_deferrals._fulfill();
          })(function() {
            if (err) {
              done(client);
              return next(err);
            }
            done();
            req.app.set('notify_modified_time', moment().format('x'));
            return res.json({
              succ: true,
              redirect: '/p1'
            });
          });
        });
      };
    })(this));
  });

  router.get('/delete/:id', body_dropdown_items, function(req, res, next) {
    var client, done, err, record, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.locals.breadcrumbs.push({
      'title': '撤销删除'
    });
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 402
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select * from pay_p1 where uuid = $1", [req.params.id], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 407
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          record = result.rows[0];
          if (!record || !record.check_data) {
            return next(new Error('未查询到记录或记录缺少待复核数据，请检查.'));
          }
          record.check_data.data.serial = record.serial;
          return res.render('p1/delete', {
            record: record.check_data.data
          });
        });
      };
    })(this));
  });

  router.post('/delete/delete', function(req, res, next) {
    var client, done, err, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 419
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("update pay_p1 set checked = true, check_data = null where uuid = $1", [req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 426
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          req.app.set('notify_modified_time', moment().format('x'));
          return res.redirect('/p1');
        });
      };
    })(this));
  });

  router.get('/check/:id', body_dropdown_items, function(req, res, next) {
    var client, done, err, name, old_value, record, result, value, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.locals.breadcrumbs.push({
      'title': '复核配置'
    });
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 437
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select p.*, u.realname as input_user from pay_p1 as p left join web_users as u on u.uuid = p.inputer where p.uuid = $1", [req.params.id], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 445
          }));
          __iced_deferrals._fulfill();
        })(function() {
          var _ref;
          if (err) {
            done(client);
            return next(err);
          }
          done();
          record = result.rows[0];
          if (!record || !record.check_data) {
            return next(new Error('未查询到记录或记录缺少待复核数据，请检查.'));
          }
          if (record.check_data.action === 2) {
            res.locals.diffs = [];
            _ref = record.check_data.data;
            for (name in _ref) {
              value = _ref[name];
              old_value = record[name] || '';
              if (value.toString() !== old_value.toString()) {
                res.locals.diffs.push(name);
              }
            }
          }
          if (record.check_data.acct_no_modified) {
            delete record.check_data.data.acct_no;
          }
          record.check_data.data.serial = record.serial;
          record.check_data.data.action = record.check_data.action;
          record.check_data.data.input_user = record.input_user;
          record.check_data.data.input_time = record.input_time;
          record.check_data.data._checking = true;
          return res.render('p1/check', {
            record: record.check_data.data
          });
        });
      };
    })(this));
  });

  router.post('/check', check_submit, function(req, res, next) {
    var check_data, client, done, err, result, ___iced_passed_deferral, __iced_deferrals, __iced_k;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 474
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select check_data from pay_p1 where checked = false and inputer <> $1 and uuid = $2", [req.session.userinfo.uuid, req.body.uuid], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 483
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          if (result.rows.length === 0) {
            return next(new Error('未查询到待复核记录，请检查.'));
          }
          check_data = result.rows[0].check_data;
          (function(__iced_k) {
            if (check_data.action === 3) {
              (function(__iced_k) {
                __iced_deferrals = new iced.Deferrals(__iced_k, {
                  parent: ___iced_passed_deferral,
                  filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
                });
                client.query("delete from pay_p1 where checked = false and inputer <> $1 and uuid = $2", [req.session.userinfo.uuid, req.body.uuid], __iced_deferrals.defer({
                  assign_fn: (function() {
                    return function() {
                      err = arguments[0];
                      return result = arguments[1];
                    };
                  })(),
                  lineno: 497
                }));
                __iced_deferrals._fulfill();
              })(function() {
                if (err) {
                  done(client);
                  return next(err);
                }
                done();
                return res.redirect('/p1');
                return __iced_k();
              });
            } else {
              return __iced_k();
            }
          })(function() {
            if (check_data.data.acct_no !== req.body.acct_no) {
              return next(new Error('您录入的收款账号与录入用户录入的不一致'));
            }
            (function(__iced_k) {
              __iced_deferrals = new iced.Deferrals(__iced_k, {
                parent: ___iced_passed_deferral,
                filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
              });
              client.query("update pay_p1 set usable = true, checked = true, checker = $1, check_time = CURRENT_TIMESTAMP, t20_merid = $2,     t20_termid = $3, tz0_merid = $4,     tz0_termid = $5, pay_chnl = $6,      pay_merid = $7, acct_no = $8,       acct_name = $9, acct_cred_no = $10, acct_cred_type = $11, acct_mobile = $12,  acct_bank_code = $13, acct_bank_name = $14,   notes = $15, check_data = null where checked = false and inputer <> $16 and uuid = $17", [req.session.userinfo.uuid, check_data.data.t20_merid, check_data.data.t20_termid, check_data.data.tz0_merid, check_data.data.tz0_termid, check_data.data.pay_chnl, check_data.data.pay_merid, check_data.data.acct_no, check_data.data.acct_name, check_data.data.acct_cred_no, parseInt(check_data.data.acct_cred_type), check_data.data.acct_mobile, check_data.data.acct_bank_code, check_data.data.acct_bank_name, check_data.data.notes, req.session.userinfo.uuid, req.body.uuid], __iced_deferrals.defer({
                assign_fn: (function() {
                  return function() {
                    err = arguments[0];
                    return result = arguments[1];
                  };
                })(),
                lineno: 536
              }));
              __iced_deferrals._fulfill();
            })(function() {
              if (err) {
                done(client);
                return next(err);
              }
              done();
              return res.redirect('/p1');
            });
          });
        });
      };
    })(this));
  });

  router.post('/pay_merids', function(req, res, next) {
    var client, done, err, k, result, ___iced_passed_deferral, __iced_deferrals, __iced_k, _i, _len, _ref;
    __iced_k = __iced_k_noop;
    ___iced_passed_deferral = iced.findDeferral(arguments);
    res.type('json');
    _ref = ['chnl'];
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
      k = _ref[_i];
      if (!req.body[k]) {
        return next(new Error("请求缺少参数[" + k + "]"));
      }
    }
    (function(_this) {
      return (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          parent: ___iced_passed_deferral,
          filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
        });
        pgsql.connect(settings.pgsql_url, __iced_deferrals.defer({
          assign_fn: (function() {
            return function() {
              err = arguments[0];
              client = arguments[1];
              return done = arguments[2];
            };
          })(),
          lineno: 547
        }));
        __iced_deferrals._fulfill();
      });
    })(this)((function(_this) {
      return function() {
        if (err) {
          done(client);
          return next(err);
        }
        (function(__iced_k) {
          __iced_deferrals = new iced.Deferrals(__iced_k, {
            parent: ___iced_passed_deferral,
            filename: "/home/qiwei/Desktop/luckpay-web/coffee/routes/p1.coffee"
          });
          client.query("select * from pay_merch where chnl = $1 and inside = false and disabled = false and shaded = false", [req.body.chnl], __iced_deferrals.defer({
            assign_fn: (function() {
              return function() {
                err = arguments[0];
                return result = arguments[1];
              };
            })(),
            lineno: 554
          }));
          __iced_deferrals._fulfill();
        })(function() {
          if (err) {
            done(client);
            return next(err);
          }
          done();
          return res.json({
            succ: true,
            merids: result.rows
          });
        });
      };
    })(this));
  });

}).call(this);
